package part14;

/**
 * @author wcj
 * @Date 2021/5/26 16:05
 * @Version 1.0
 */
public class Part150 {

    /**
     * instanceof和isInstance()比较的结果都是依据是否在继承关系上，而==和equals()这比较是否为本类
     *
     * @param x
     */
    public static void test(Object x) {
        System.out.println("Testing x of type:" + x.getClass());
        System.out.println("x instanceof Base:" + (x instanceof Base));
        System.out.println("x instanceof Derived:" + (x instanceof Derived));
        System.out.println("Base isInstance(x):" + Base.class.isInstance(x));
        System.out.println("Derived isInstance(x):" + Derived.class.isInstance(x));
        System.out.println("x.getClass() == Base.class:" + (x.getClass() == Base.class));
        System.out.println("x.getClass() == Derived.class:" + (x.getClass() == Derived.class));
        System.out.println("x.getClass().equals(Base.class):" + x.getClass().equals(Base.class));
        System.out.println("x.getClass().equals(Derived.class):" + x.getClass().equals(Derived.class));
    }

    public static void main(String[] args) {
        // Base.class  true false true false true false true false
//        test(new Base());
        // Derived.class true tue false true false true false true
        test(new Derived());
    }
}

class Base {
}

class Derived extends Base {
}
